@Slf4j
public class DynamicPersistenceProviderResolver implements PersistenceProviderResolver {
    
    private final MultiDataSourceProperties properties;
    private final Map<String, PersistenceProvider> providers = new ConcurrentHashMap<>();
    
    public DynamicPersistenceProviderResolver(MultiDataSourceProperties properties) {
        this.properties = properties;
    }
    
    public PersistenceProvider getProvider(String dataSourceName) {
        return providers.computeIfAbsent(dataSourceName, this::createProvider);
    }
    
    private PersistenceProvider createProvider(String dataSourceName) {
        DataSourceProperties config = properties.getSources().get(dataSourceName);
        if (config == null) {
            throw new IllegalArgumentException("Unknown data source: " + dataSourceName);
        }
        
        switch (config.getPersistenceType()) {
            case JPA:
                return new JpaPersistenceProvider();
            case MYBATIS:
                return new MybatisPersistenceProvider();
            case JDBC:
                return new JdbcPersistenceProvider();
            default:
                throw new IllegalStateException("Unsupported persistence type: " 
                    + config.getPersistenceType());
        }
    }
} 